package com.zhao.dota.processor;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.zhao.dota.common.processor.SteamProcessor;
import com.zhao.dota.struct.SteamResult;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 获取英雄信息
 */
@Component
@Slf4j
public class HeroProcessor extends SteamProcessor {

    private static final String URL = "https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v1";
//    http://www.dota2.com/jsfeed/heropickerdata/cn 开放数据
//    https://www.dota2.com/datafeed/herolist?language=schinese
//    https://docs.stratz.com/index.html

    public SteamResult<Container> getHeroList() {
        Request request = super.buildGet(URL, new Param("language", "zh-cn"));
        String result = super.sendRequest(request);
        SteamResult<Container> heroListResult = super.readValue(result, new TypeReference<SteamResult<Container>>() {
        });
        return heroListResult;
    }

    @Data
    public static class Container {

        private List<HeroProcessor.Hero> heroes;

        private int status;

        private int count;

    }

    @Data
    public static class Hero {

        private int id;

        @JsonProperty("localized_name")
        private String localizedName;

        private String name;

    }

}
